<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of c_table
 *
 * @author tonatos
 */
class c_table {

        var $numCols;
        var $headings;    // array of the headings $object->headings = array('Business','Contact Name');

        // table style - Setting font sizes decorations etc...
        var $headingStyle;      // style for the heading row
        var $rowLightStyle;     // style for the lighter colored rows
        var $rowDarkStyle;      // style for the darker colored rows
        var $rowHighlightStyle; // style for the highlighted row

        var $colStyle;   // array of style tags for each column (not implemented)

        // basic table settings
        var $cellpadding;
        var $cellspacing;
        var $tableWidth;
        var $tablestyle;

        // cell borders
        var $cellborder;        // another style tag for each cell


        var $row;              // array $row[row][column]
        var $numRows;      // row counter
        // Constructor
        function  __construct() {

                // this sets up the default values
                // if all of your tables are going to look the same you can put all
                // of your style information in here and it will make using the table class easier
                $this->headingStyle = "";


                $this->cellpadding = 3;
                $this->cellspacing = 0;

                $this->cellborder = "border: solid 1px #000000;";

                $this->numRows = 0;
                $this->numCols = 0;
        }

	function setHead($heads){
		$this->numCols = count($heads);
		$this->headings = $heads;

	}


	function addData($data){

		foreach($data as $row){
			$this->addRow($row);
		}		
	}

        function addRow($rowData){

                for ( $i=0; $i<$this->numCols; $i++ ){
                        if ($rowData[$i])
                                $this->row[$this->numRows][$i] = $rowData[$i];
                        else
                                $this->row[$this->numRows][$i] = "&nbsp;";
                }

                $this->numRows++;
        }

        function show(){

                echo '<table cellpadding="0" cellspacing="0" border="0" class="dataTable display black">';
                echo '<thead>';
                echo "<tr>\r\n";

		foreach($this->headings as $head){
                        echo "<th>$head</th>";
                }

                echo "</tr>\r\n";
                echo '</thead>';
                echo '<tbody>';
                for ( $r=0; $r<$this->numRows; $r++ ){

                        $cRowClass = (fmod($r,2))?"odd":"even";
                        echo "<tr class=\"" . $cRowClass . "\"";
                        echo ">\r\n";
                        for ( $c=0; $c<$this->numCols; $c++ ){
                                echo "<td>" . $this->row[$r][$c] . "</td>";
                        }
                        echo "\r\n</tr>\r\n";
                }
                echo '</tbody>';
                echo "</table>";
        }

}
?>
